//
//  DSUnitView.m
//  DSJY
//
//  Created by 冯华强 on 16/9/29.
//  Copyright © 2016年 dsjy. All rights reserved.
//  单元练习左右View

#import "DSUnitView.h"
#import "DSUnitBorderView.h"
#import "DSUnitInnerView.h"
#import "Masonry.h"
#import "DSUnitListeningContent.h"

@interface DSUnitView ()
//内部的View
@property (nonatomic, weak, readwrite) DSUnitInnerView *unitInnerView;
//选中背景的View
@property (nonatomic, weak, readwrite) DSUnitBorderView *unitBorderView;
//hq_test
@property(nonatomic, weak) UILabel *answerLabel;
@end

@implementation DSUnitView

#pragma mark - 系统回调
+ (__kindof DSUnitView *)unitView
{
    return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        [self setupView];
    }
    return self;
}

#pragma mark - 设置UI
- (void)setupView
{
    //内部的View
    DSUnitInnerView *unitInnerView = [DSUnitInnerView unitInnerView];
    [self addSubview:unitInnerView];
    self.unitInnerView = unitInnerView;
    
    //选中背景的View
    DSUnitBorderView *unitBorderView = [DSUnitBorderView unitBorderView];
    unitBorderView.backgroundColor = [UIColor clearColor];
    [self addSubview:unitBorderView];
    self.unitBorderView = unitBorderView;
    
    //hq_test
    UILabel *answerLabel = [[UILabel alloc] init];
    //hq_test
    answerLabel.hidden = YES;
    answerLabel.textColor = [UIColor redColor];
    [self addSubview:answerLabel];
    self.answerLabel = answerLabel;
    
    [unitInnerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.width.mas_equalTo(UnitInnerViewW);
        make.height.mas_equalTo(UnitInnerViewH);
    }];
    
    [unitBorderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.and.width.height.equalTo(unitInnerView);
    }];
    
    //hq_test
    [answerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.and.width.height.equalTo(unitInnerView);
    }];
}

- (void)setListeningContent:(DSUnitListeningContent *)listeningContent
{
    _listeningContent = listeningContent;
    
    self.unitInnerView.listeningContent = listeningContent;
    //hq_test
//    self.answerLabel.text = listeningContent.nameString;
}


@end
